// const { get } = require("../../until/db");
import {get} from "../../until/db"
 // pages/list/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists:[]
  },
  async onLoad(e){
    // console.log(e,"-------");
    var classId= e.id;
    var name = e.name
    wx.setNavigationBarTitle({
      title: name,
    })
    var result = await get("menu",{classId})
    // console.log(result);
    var lists =result.data
    // console.log(lists);
    lists.forEach(item=>{
      if(item.views==0){
        item.star=0
      }else if(item.views>0 && item.views<=10){
        item.star=1;
      }else if(item.views>10 && item.views<=20){
        item.star=2
      }else if(item.views>20 && item.views<=30){
        item.star=3
      }else if(item.views>30 && item.views<=40){
        item.star=4;
      }else{
        item.star=5
      }
    })
    this.setData({
      lists
    })
  },
  toDetail(e){
    console.log(e);
    var id = e.currentTarget.id
    var name = e.currentTarget.dataset.name
    // console.log(id);
    wx.navigateTo({
      url: '/pages/detail/detail?id='+id+'&name='+name,
    })
  },
 
 
})